Skip to content

Add comprehensive tests for the query-and-write insert command#597

Merged
eerxuan merged 13 commits into
documentdb:mainfrom
imforster:forstaia/insert/query-and-write
Jun 16, 2026
Merged

Add comprehensive tests for the query-and-write insert command#597
eerxuan merged 13 commits into
documentdb:mainfrom
imforster:forstaia/insert/query-and-write

Conversation

@imforster

Copy link
Copy Markdown
Collaborator

#39

Feature: query-and-write insert command
Test cases: 253
Docs: https://www.mongodb.com/docs/v8.2/reference/command/insert/

Adds compatibility test coverage for the query-and-write insert command, validating its full surface area - from basic document insertion and implicit collection creation to BSON type preservation, ordered/unordered error handling, _id field semantics, schema validation, and argument type rejection - across document types and edge cases.

253 test cases across 13 files following project test guidelines.

Also renames the query-and-write directory tree to use underscores (query_and_write) for valid Python package naming, and renames read-concern and write-concern subdirectories accordingly.

@imforster imforster requested a review from a team as a code owner June 11, 2026 21:28
@imforster imforster force-pushed the forstaia/insert/query-and-write branch from 7fbe2bc to b3d793b Compare June 11, 2026 22:21
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, enhancement
Project fields suggested: Component test-coverage · Priority P2 · Effort XL · Status Needs Review
Confidence: 0.90 (mixed)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (2323+33 LOC, 43 files); LLM: Adds 253 new compatibility test cases across 13 files for the insert command, plus a directory rename affecting the query-and-write tree — multi-file, single component, no schema change.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels Jun 11, 2026
@imforster imforster force-pushed the forstaia/insert/query-and-write branch from b3d793b to d0a1030 Compare June 11, 2026 22:41
Comment thread documentdb_tests/framework/test_constants.py Outdated

@eerxuan eerxuan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About 40-45% of the cases duplicate centralized sites, concentrated in two files:

  • test_insert_bson_type_preservation.py — should be deleted, ~10 net-new cases moved to bson_types/types/
  • test_insert_numeric_and_datetime_boundaries.py — should be deleted, ~6 net-new cases moved to bson_types/types/

Plus a smaller cleanup pass:

  • 15-case namespace BSON matrix in argument_handling.py → 1-2 wiring cases (consistent with §19, inconsistent with the rest of the repo — see my earlier point about this being a repo-wide problem)
  • ARRAY_TESTS, STRUCTURE_TESTS in document_structure.py → drop
  • empty_documents_array duplicated between two files → drop one
  • test_insert_capped_collection_wraps_old_documents → drop (capped/ owns it)

imforster added 11 commits June 15, 2026 11:13
Feature: query-and-write insert command
Test cases: 253
Docs: https://www.mongodb.com/docs/v8.2/reference/command/insert/

Adds compatibility test coverage for the query-and-write insert
command, validating its full surface area - from basic document
insertion and implicit collection creation to BSON type preservation,
ordered/unordered error handling, _id field semantics, schema
validation, and argument type rejection - across document types and
edge cases.

253 test cases across 13 files following project test guidelines.

Also renames the query-and-write directory tree to use underscores
(query_and_write) for valid Python package naming, and renames
read-concern and write-concern subdirectories accordingly.

Signed-off-by: Ian Forster <forstaia@amazon.com>
Feature: query-and-write insert command
Test cases: 253
Docs: https://www.mongodb.com/docs/v8.2/reference/command/insert/

Adds compatibility test coverage for the query-and-write insert
command, validating its full surface area - from basic document
insertion and implicit collection creation to BSON type preservation,
ordered/unordered error handling, _id field semantics, schema
validation, and argument type rejection - across document types and
edge cases.

253 test cases across 13 files following project test guidelines.

Also renames the query-and-write directory tree to use underscores
(query_and_write) for valid Python package naming, and renames
read-concern and write-concern subdirectories accordingly.

Signed-off-by: Ian Forster <forstaia@amazon.com>

# Conflicts:
#	documentdb_tests/compatibility/tests/core/operator/stages/rankFusion/test_rankFusion_metadata.py
#	documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_operations.py

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# interactive rebase in progress; onto e3c5c35
# Last command done (1 command done):
#    pick d0a1030 # Add comprehensive tests for the query-and-write insert command
# Next commands to do (10 remaining commands):
#    pick fdfcbc6 # Refactor insert tests to use CommandTestCase pattern
#    pick 32c79d0 # Fix plain assert in test_insert_id_handling causing unit test validation failure
# You are currently rebasing branch 'forstaia/insert/query-and-write' on 'e3c5c35'.
#
# Changes to be committed:
#	modified:   documentdb_tests/compatibility/tests/core/operator/stages/rankFusion/test_rankFusion_metadata.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_argument_handling.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_batch_size_limits.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_bson_type_preservation.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_bypass_validation.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_collection_variants.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_core_behavior.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_document_structure.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_id_handling.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_numeric_and_datetime_boundaries.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_ordered_and_errors.py
#	new file:   documentdb_tests/compatibility/tests/core/query_and_write/commands/insert/test_insert_write_concern.py
#	modified:   documentdb_tests/framework/test_constants.py
#
# Untracked files:
#	graphify-out/
#
…ion failure

Replace assert isinstance(expected, dict) with cast(Dict[str, Any], ...)
to satisfy mypy type narrowing without triggering the test format
validator which prohibits plain assert statements in test functions.

Signed-off-by: Ian Forster <forstaia@amazon.com>
Raw bytes are converted by the driver on read; use Binary to preserve
the expected type consistently across all type sample consumers.

Signed-off-by: Ian Forster <forstaia@amazon.com>
main relocated command_test_case.py from:
  core/collections/commands/utils/
to:
  core/utils/

Update all four insert test files to use the new path.

Signed-off-by: Ian Forster <forstaia@amazon.com>
…_succeeds

The old name implied boundary coverage of maxWriteBatchSize but the
implementation inserted only 1,000 docs (three orders of magnitude
under the 100,000 limit). Rename to accurately reflect intent and add
a docstring explaining this is a wiring test, not a limit test.

Signed-off-by: Ian Forster <forstaia@amazon.com>
DBRef is a client-side convention enforced by the driver, not a
server-side feature. The server treats $ref/$id as plain fields.
The test was not exercising any server behavior.

Signed-off-by: Ian Forster <forstaia@amazon.com>
test_insert_null_field_exists, test_insert_missing_field_not_null, and
test_insert_timestamp_zero_gets_autofilled are genuinely insert-command
behaviors, not BSON round-trip tests. Move them to test_insert_core_behavior
where they belong, ahead of deleting the bson_type_preservation file.

Signed-off-by: Ian Forster <forstaia@amazon.com>
The BSON round-trip matrix (BSON_TYPE_TESTS, INT64_BOUNDARY_TESTS,
DOUBLE_SPECIAL_TESTS, DATE_BOUNDARY_TESTS, TIMESTAMP_BOUNDARY_TESTS,
OID_BOUNDARY_TESTS, DECIMAL128_PRECISION_TESTS, BINARY_SUBTYPE_TESTS,
BSON_DISTINCTION_TESTS) materially duplicates the coverage already
owned by data-types/bson_types/types/ via RoundTripTestCase.

The three insert-command-specific tests (null field semantics,
missing field, Timestamp(0,0) auto-fill) were moved to
test_insert_core_behavior.py in the previous commit.

Signed-off-by: Ian Forster <forstaia@amazon.com>
Per TEST_COVERAGE.md §19, wire-protocol namespace validation
(INVALID_NAMESPACE_ERROR for non-string collection name types) is
foundational behavior that should have a single centralized test site.
Per-command duplication of the full BSON type matrix scales linearly
with command count and drifts when the canonical set changes.

- Replace 15 insert_field_rejects_* cases with one representative
  case (insert_field_rejects_non_string using int) in
  test_insert_argument_handling.py
- Remove now-unused INT64_MAX import from test_constants

Signed-off-by: Ian Forster <forstaia@amazon.com>
- Delete test_insert_numeric_and_datetime_boundaries.py: numeric
  round-trip cases duplicate test_types_numeric.py; DatetimeMS cases
  moved to test_types_date.py (net-new).
- Drop ARRAY_TESTS and STRUCTURE_TESTS from test_insert_document_structure.py:
  generic BSON preservation behavior, not insert-specific.
- Drop empty_documents_array from test_insert_argument_handling.py:
  duplicate of test_insert_batch_size_limits.py (canonical location).
- Drop test_insert_capped_collection_wraps_old_documents from
  test_insert_collection_variants.py: capped collection eviction
  behavior belongs in capped/ tests.

Signed-off-by: Ian Forster <forstaia@amazon.com>
@imforster imforster force-pushed the forstaia/insert/query-and-write branch from a4cb369 to 0f7f6fd Compare June 15, 2026 18:15
@imforster imforster requested a review from vic-tsang June 15, 2026 18:27
- Add JavaScript Code type to CUSTOM_ID_TYPE_TESTS for BSON exhaustiveness
- Add test_insert_nan_id_accepted: NaN is valid as _id
- Add test_insert_nan_id_duplicate: two NaN _ids collide as duplicate keys

Signed-off-by: Ian Forster <forstaia@amazon.com>
@eerxuan eerxuan merged commit 340a44e into documentdb:main Jun 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility test Compatibility test related enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants